package com.ccnu.sb.manage;

import com.ccnu.sb.dao.pojo.TCust;
import com.ccnu.sb.exception.RspException;
import com.ccnu.sb.system.AppTools;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class LoginMan {
//	@Autowired
//	private UserInfoServiceImp userOpr;
	
	private static Logger log = LogManager.getLogger();

	/**
	 * @param reqMap
	 * @return
	 */
	public String SignUp(Map<String,Object> reqMap) {
		log.info("LoginController.SignUp entry");
//		UserInfo user = new UserInfo();
//
//		String userNo = reqMap.get("no").toString();
//		if(userNo.isEmpty()) {
//			throw new RspException("0001", "用户号不能为空");
//		}
//		user.setUserNo(userNo);
//		user.setUserName(reqMap.get("name").toString());
//		user.setPassword(reqMap.get("password").toString());
//		user.setAddress(reqMap.get("address").toString());
//		user.setEmail(reqMap.get("email").toString());
//		user.setMobile(reqMap.get("mobile").toString());
//
//		userOpr.insert(user);
		
		Map<String, String> rspMap = new HashMap<String, String>();
		rspMap.put("rspCode", "0000");
		rspMap.put("rspMsg", "注册成功");
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = null;
		try {
			jsonString = mapper.writeValueAsString(rspMap);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return jsonString;
	}
	
	public String Login(Map<String,Object> reqMap) {
//		UserInfo user = new UserInfo();
		
//		String userNo = AppTools.GetParam(reqMap, "no");
//		if(userNo==null || userNo.isEmpty()) {
//			throw new RspException("0001", "用户号不能为空");
//		}
//		String password = AppTools.GetParam(reqMap, "password");
//		if(password.isEmpty()) {
//			throw new RspException("0001", "密码不能为空");
//		}
//		// 检查用户密码是否匹配
//		user.setUserNo(userNo);
//		user.setPassword(password);
//		UserInfo userDb = userOpr.selectByPrimaryKey(user.getUserNo());
//		if(userDb==null) {
//			throw new RspException("0001", "用户名与账号不匹配");
//		}
//
//		if( !user.getPassword().equals(userDb.getPassword())) {
//			throw new RspException("0001", "密码不正确");
//		}
//
		Map<String, String> rspMap = new HashMap<String, String>();
		rspMap.put("rspCode", "0000");
		rspMap.put("rspMsg", "客户密码成功");
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = null;
		try {
			jsonString = mapper.writeValueAsString(rspMap);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return jsonString;
	}
	
	public boolean CacheUser(Map<String,Object> reqMap) {
//		return userOpr.CacheUserInfo();
		return true;
	}

	public List<TCust> ListCacheUser() {
//		return userOpr.ListCacheUser();
		return null;
	}
}
